/* Grammar for Assembler */
%{
#include "assembler.h"
#include "isa.h"
%}

/* Part 1: declarations*/
LETTER		\'[^ \t\r\n]\'
LABEL		[a-zA-Z_][0-9a-zA-Z_]*:
STRING		[a-zA-Z_][0-9a-zA-Z_]*
REGS		%ra|%rb|%rc|%rd|%sp|%bp|%si|%di|%ih|%pdir|%flags
INSTR		halt|nop|rrmov|irmov|store|load|add|sub|and|or|not|xor|shl|shr|jmp|je|jl|jg|jne|jle|jge|call|int|ret|iret|push|pop|in|out
DIGIT		[0-9]
HEX_DIGIT	[0-9a-fA-F]
HEX_INTEGER	0[xX]{HEX_DIGIT}+
DEC_INTEGER	{DIGIT}+
NEWLINE		\r|\n|\r\n
COMMENT		"//"[^\r\n]*{NEWLINE}
BLANK		[, \t()]

/* Part 2: rules */
%x ERR COM
%%

;		add_stmt();
{INSTR}		add_instr(yytext);
{LABEL}		add_label(yytext);
{STRING}	add_addr(yytext);
{REGS}		add_reg(yytext);
{LETTER}	add_letter(yytext);
{HEX_INTEGER}	add_hex(yytext);
{DEC_INTEGER}	add_dec(yytext);
{NEWLINE}	{}
{BLANK}		{}
{COMMENT}	{}
%%

/* Part 3: auxiliary functions*/
